package me.azthink.myblog.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import me.azthink.myblog.domain.Site;
import me.azthink.myblog.utils.DBUtils;

/** 
  *   站点数据访问对象
 * @author Administrator
 *
 */
public class SiteDAO {
	//获取站点信息
	public Site findById(int id) throws SQLException {
		
		//1.获取链接
		Connection conn = DBUtils.getConnection();
		
		//2.拼接SQL
		String sql = "select * from site where id=?";
		
		//3.获取执行者，放松SQL
		PreparedStatement st = conn.prepareStatement(sql);
		st.setInt(1,id);
		ResultSet rs = st.executeQuery();
		
		//4.处理结果
		Site site = null;
		while(rs.next()) {
			site = new Site();
			site.setId(rs.getInt("id"));
			site.setTitle(rs.getString("title"));
			site.setLogo(rs.getString("logo"));
			site.setTheme(rs.getString("theme"));
			site.setRemark(rs.getString("remark"));
		}
		
		//5.关闭资源
		DBUtils.closeResource(conn, st,rs);
		return site;
	}
}
